
const http = require('http')
const server = http.createServer()

server.on('request' , (req,res)=>{

  const url = req.url     //获取URL地址

  // console.log(url)
  let content = '<h4>404 not found</h4>'  //设置默认的响应内容

  if(url == '/' || url == '/index.html'){
    content = '<h1>首页</h1>'
  }

  if(url == '/about.html'){
    content = '<h1>关于</h1>'
  }

  // 调用res.setHeader放法，设置content-Type 响应头，解决中文乱码问题
  res.setHeader('Content-Type' ,'text/html;charset=utf-8' )
  
  res.end(content)
})

server.listen(8080 , ()=>{

})